﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class LocationTemplateDA : ILocationTemplateDA
    {
        private string CREATED_BY = "@CREATED_BY";
        private string FIELD1_DESC = "@FIELD1_DESC";
        private string FIELD1_LENGTH = "@FIELD1_LENGTH";
        private string FIELD1_TYPE = "@FIELD1_TYPE";
        private string FIELD2_DESC = "@FIELD2_DESC";
        private string FIELD2_LENGTH = "@FIELD2_LENGTH";
        private string FIELD2_TYPE = "@FIELD2_TYPE";
        private string FIELD3_DESC = "@FIELD3_DESC";
        private string FIELD3_LENGTH = "@FIELD3_LENGTH";
        private string FIELD3_TYPE = "@FIELD3_TYPE";
        private string FIELD4_DESC = "@FIELD4_DESC";
        private string FIELD4_LENGTH = "@FIELD4_LENGTH";
        private string FIELD4_TYPE = "@FIELD4_TYPE";
        private string FIELD5_DESC = "@FIELD5_DESC";
        private string FIELD5_LENGTH = "@FIELD5_LENGTH";
        private string FIELD5_TYPE = "@FIELD5_TYPE";
        private string IS_ACTIVE = "@IS_ACTIVE";
        private string LOC_TEMPLATE_ID = "@LOC_TEMPLATE_ID";
        private string SEPERATOR_CHAR = "@SEPERATOR_CHAR";
        private string SQL_CHECK_LOCATION_TEMPLATE_ID_UNIQUE = " SELECT COUNT(1) FROM @_@LOCATION_TEMPLATE WHERE LOC_TEMPLATE_ID = @LOC_TEMPLATE_ID ";
        private string SQL_DELETE_LOCATION_TEMPLATE = " DELETE FROM @_@LOCATION_TEMPLATE WHERE LOC_TEMPLATE_ID = @LOC_TEMPLATE_ID ";
        private string SQL_INSERT_LOCATION_TEMPLATE = " INSERT INTO @_@LOCATION_TEMPLATE ( WH_ID, LOC_TEMPLATE_ID, FIELD1_LENGTH, FIELD1_TYPE, FIELD1_DESC, FIELD2_LENGTH, FIELD2_TYPE, FIELD2_DESC, FIELD3_LENGTH, FIELD3_TYPE, FIELD3_DESC, FIELD4_LENGTH, FIELD4_TYPE, FIELD4_DESC, FIELD5_LENGTH, FIELD5_TYPE, FIELD5_DESC, SEPERATOR_CHAR, IS_ACTIVE, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @LOC_TEMPLATE_ID, @FIELD1_LENGTH, @FIELD1_TYPE, @FIELD1_DESC, @FIELD2_LENGTH, @FIELD2_TYPE, @FIELD2_DESC, @FIELD3_LENGTH, @FIELD3_TYPE, @FIELD3_DESC, @FIELD4_LENGTH, @FIELD4_TYPE, @FIELD4_DESC, @FIELD5_LENGTH, @FIELD5_TYPE, @FIELD5_DESC, @SEPERATOR_CHAR, @IS_ACTIVE, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_LOCATION_TEMPLATE = " SELECT  ROWID, WH_ID, LOC_TEMPLATE_ID, FIELD1_LENGTH, FIELD1_TYPE, FIELD1_DESC, FIELD2_LENGTH, FIELD2_TYPE, FIELD2_DESC, FIELD3_LENGTH, FIELD3_TYPE, FIELD3_DESC, FIELD4_LENGTH, FIELD4_TYPE, FIELD4_DESC, FIELD5_LENGTH, FIELD5_TYPE, FIELD5_DESC, SEPERATOR_CHAR, IS_ACTIVE, TS, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE  FROM  @_@LOCATION_TEMPLATE ";
        private string SQL_UPDATE_LOCATION_TEMPLATE = " UPDATE @_@LOCATION_TEMPLATE SET WH_ID = @WH_ID, FIELD1_LENGTH = @FIELD1_LENGTH, FIELD1_TYPE = @FIELD1_TYPE, FIELD1_DESC = @FIELD1_DESC, FIELD2_LENGTH = @FIELD2_LENGTH, FIELD2_TYPE = @FIELD2_TYPE, FIELD2_DESC = @FIELD2_DESC, FIELD3_LENGTH = @FIELD3_LENGTH, FIELD3_TYPE = @FIELD3_TYPE, FIELD3_DESC = @FIELD3_DESC, FIELD4_LENGTH = @FIELD4_LENGTH, FIELD4_TYPE = @FIELD4_TYPE, FIELD4_DESC = @FIELD4_DESC, FIELD5_LENGTH = @FIELD5_LENGTH, FIELD5_TYPE = @FIELD5_TYPE, FIELD5_DESC = @FIELD5_DESC, SEPERATOR_CHAR = @SEPERATOR_CHAR, IS_ACTIVE = @IS_ACTIVE, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE LOC_TEMPLATE_ID = @LOC_TEMPLATE_ID  ";
        private string TS = "@TS";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckLocationTemplateIDUnique(string locationTemplateID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOC_TEMPLATE_ID", locationTemplateID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_LOCATION_TEMPLATE_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckLocationTemplateIDUnique(DataBase dataBase, DbTransaction tran, string locationTemplateID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOC_TEMPLATE_ID", locationTemplateID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_LOCATION_TEMPLATE_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteLocationTemplate(List<string> locationTemplateID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < locationTemplateID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOC_TEMPLATE_ID", locationTemplateID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_LOCATION_TEMPLATE.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteLocationTemplate(DataBase dataBase, DbTransaction tran, List<string> locationTemplateID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < locationTemplateID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOC_TEMPLATE_ID", locationTemplateID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_LOCATION_TEMPLATE.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllLocationTemplate(string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_LOCATION_TEMPLATE.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllLocationTemplate(DataBase dataBase, DbTransaction tran, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_LOCATION_TEMPLATE.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public LocationTemplateInfo GetLocationTemplateByID(string locationtemplateID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_LOCATION_TEMPLATE.Replace("@_@", whLoginID) + " WHERE LOC_TEMPLATE_ID = @LOC_TEMPLATE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOC_TEMPLATE_ID", locationtemplateID) };
            LocationTemplateInfo locationTemplateInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    locationTemplateInfo = new LocationTemplateInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["LOC_TEMPLATE_ID"].ToString(), (reader["FIELD1_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD1_LENGTH"].ToString()) : 0, reader["FIELD1_TYPE"].ToString(), reader["FIELD1_DESC"].ToString(), (reader["FIELD2_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD2_LENGTH"].ToString()) : 0, reader["FIELD2_TYPE"].ToString(), reader["FIELD2_DESC"].ToString(), (reader["FIELD3_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD3_LENGTH"].ToString()) : 0, reader["FIELD3_TYPE"].ToString(), reader["FIELD3_DESC"].ToString(), (reader["FIELD4_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD4_LENGTH"].ToString()) : 0, reader["FIELD4_TYPE"].ToString(), reader["FIELD4_DESC"].ToString(), (reader["FIELD5_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD5_LENGTH"].ToString()) : 0, reader["FIELD5_TYPE"].ToString(), reader["FIELD5_DESC"].ToString(), reader["SEPERATOR_CHAR"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
                }
            }
            return locationTemplateInfo;
        }

        public LocationTemplateInfo GetLocationTemplateByID(DataBase dataBase, DbTransaction tran, string locationtemplateID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_LOCATION_TEMPLATE.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LOC_TEMPLATE_ID", locationtemplateID) };
            LocationTemplateInfo locationTemplateInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                locationTemplateInfo = new LocationTemplateInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["LOC_TEMPLATE_ID"].ToString(), (reader["FIELD1_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD1_LENGTH"].ToString()) : 0, reader["FIELD1_TYPE"].ToString(), reader["FIELD1_DESC"].ToString(), (reader["FIELD2_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD2_LENGTH"].ToString()) : 0, reader["FIELD2_TYPE"].ToString(), reader["FIELD2_DESC"].ToString(), (reader["FIELD3_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD3_LENGTH"].ToString()) : 0, reader["FIELD3_TYPE"].ToString(), reader["FIELD3_DESC"].ToString(), (reader["FIELD4_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD4_LENGTH"].ToString()) : 0, reader["FIELD4_TYPE"].ToString(), reader["FIELD4_DESC"].ToString(), (reader["FIELD5_LENGTH"].ToString() != "") ? int.Parse(reader["FIELD5_LENGTH"].ToString()) : 0, reader["FIELD5_TYPE"].ToString(), reader["FIELD5_DESC"].ToString(), reader["SEPERATOR_CHAR"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return locationTemplateInfo;
        }

        public DataSet GetLocationTemplateByQueryList(List<string> sqlWhere, LocationTemplateQueryEntity locationtemplateQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_LOCATION_TEMPLATE.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!locationtemplateQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, locationtemplateQuery.CurrentPage, locationtemplateQuery.PageSize, locationtemplateQuery.SortField, locationtemplateQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetLocationTemplateByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, LocationTemplateQueryEntity locationtemplateQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_LOCATION_TEMPLATE.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!locationtemplateQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, locationtemplateQuery.CurrentPage, locationtemplateQuery.PageSize, locationtemplateQuery.SortField, locationtemplateQuery.SortDirection);
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int InsertLocationTemplate(LocationTemplateInfo locationTemplateInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    locationTemplateInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_LocationTemplate_Parameters(locationTemplateInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_LOCATION_TEMPLATE.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                conn.Close();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertLocationTemplate(DataBase dataBase, DbTransaction tran, LocationTemplateInfo locationTemplateInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    locationTemplateInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_LocationTemplate_Parameters(locationTemplateInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_LOCATION_TEMPLATE.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_LocationTemplate_Parameters(LocationTemplateInfo locationTemplateInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.LOC_TEMPLATE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.FIELD1_LENGTH, SqlDbType.Int, 4), new SqlParameter(this.FIELD1_TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.FIELD1_DESC, SqlDbType.VarChar, 50), new SqlParameter(this.FIELD2_LENGTH, SqlDbType.Int, 4), new SqlParameter(this.FIELD2_TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.FIELD2_DESC, SqlDbType.VarChar, 50), new SqlParameter(this.FIELD3_LENGTH, SqlDbType.Int, 4), new SqlParameter(this.FIELD3_TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.FIELD3_DESC, SqlDbType.VarChar, 50), new SqlParameter(this.FIELD4_LENGTH, SqlDbType.Int, 4), new SqlParameter(this.FIELD4_TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.FIELD4_DESC, SqlDbType.VarChar, 50), new SqlParameter(this.FIELD5_LENGTH, SqlDbType.Int, 4), new SqlParameter(this.FIELD5_TYPE, SqlDbType.VarChar, 20), 
                new SqlParameter(this.FIELD5_DESC, SqlDbType.VarChar, 50), new SqlParameter(this.SEPERATOR_CHAR, SqlDbType.VarChar, 1), new SqlParameter(this.IS_ACTIVE, SqlDbType.VarChar, 1), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20)
             };
            if (!string.IsNullOrEmpty(locationTemplateInfo.WhID))
            {
                paramArray[0].Value = locationTemplateInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = locationTemplateInfo.LocTemplateID;
            paramArray[2].Value = locationTemplateInfo.Field1Length;
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field1Type))
            {
                paramArray[3].Value = locationTemplateInfo.Field1Type;
            }
            else
            {
                paramArray[3].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field1Desc))
            {
                paramArray[4].Value = locationTemplateInfo.Field1Desc;
            }
            else
            {
                paramArray[4].Value = DBNull.Value;
            }
            paramArray[5].Value = locationTemplateInfo.Field2Length;
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field2Type))
            {
                paramArray[6].Value = locationTemplateInfo.Field2Type;
            }
            else
            {
                paramArray[6].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field2Desc))
            {
                paramArray[7].Value = locationTemplateInfo.Field2Desc;
            }
            else
            {
                paramArray[7].Value = DBNull.Value;
            }
            paramArray[8].Value = locationTemplateInfo.Field3Length;
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field3Type))
            {
                paramArray[9].Value = locationTemplateInfo.Field3Type;
            }
            else
            {
                paramArray[9].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field3Desc))
            {
                paramArray[10].Value = locationTemplateInfo.Field3Desc;
            }
            else
            {
                paramArray[10].Value = DBNull.Value;
            }
            paramArray[11].Value = locationTemplateInfo.Field4Length;
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field4Type))
            {
                paramArray[12].Value = locationTemplateInfo.Field4Type;
            }
            else
            {
                paramArray[12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field4Desc))
            {
                paramArray[13].Value = locationTemplateInfo.Field4Desc;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            paramArray[14].Value = locationTemplateInfo.Field5Length;
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field5Type))
            {
                paramArray[15].Value = locationTemplateInfo.Field5Type;
            }
            else
            {
                paramArray[15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(locationTemplateInfo.Field5Desc))
            {
                paramArray[0x10].Value = locationTemplateInfo.Field5Desc;
            }
            else
            {
                paramArray[0x10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(locationTemplateInfo.SeperatorChar))
            {
                paramArray[0x11].Value = locationTemplateInfo.SeperatorChar;
            }
            else
            {
                paramArray[0x11].Value = DBNull.Value;
            }
            paramArray[0x12].Value = locationTemplateInfo.IsActive;
            paramArray[0x13].Value = locationTemplateInfo.CreatedBy;
            paramArray[20].Value = locationTemplateInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateLocationTemplate(LocationTemplateInfo locationTemplateInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    locationTemplateInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_LocationTemplate_Parameters(locationTemplateInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_LOCATION_TEMPLATE.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateLocationTemplate(DataBase dataBase, DbTransaction tran, LocationTemplateInfo locationTemplateInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    locationTemplateInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_LocationTemplate_Parameters(locationTemplateInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_LOCATION_TEMPLATE.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

